package com.example.tuyou.myapplication;

import android.content.ContentUris;
import android.content.Context;
import android.content.UriMatcher;
import android.net.Uri;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

    /**
     * 操作Uri辅助类
     */
    @Test
    public void ContentUris() {
        // Context of the app under test.
//        Context appContext = InstrumentationRegistry.getTargetContext();
//        assertEquals("com.example.tuyou.myapplication", appContext.getPackageName());


        Uri uri = Uri.parse("content://com.tuyou.mycontentprovider/user/");
        Uri resultUri = ContentUris.withAppendedId(uri, 1);
        System.out.println(resultUri);

        uri = Uri.parse("content://com.tuyou.mycontentprovider/user/7");
        long id = ContentUris.parseId(uri);
        System.out.println(id);
    }

    /**
     * 向ContentProvider注册Uri
     * 根据Uri匹配ContentProvider中对应的数据表
     */
    @Test
    public void UriMatcher(){

        UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        int URI_CODE_a = 1;
        int URI_CODE_b = 2;
        uriMatcher.addURI("com.tuyou.mycontentprovider", "user1", URI_CODE_a);
        uriMatcher.addURI("com.tuyou.mycontentprovider", "user2", URI_CODE_b);

    }

    /**
     * 内容观察者
     */
    @Test
    public void ContentObserver(){

    }
}
